package 力扣._6952_统计趣味子数组的数目;

import java.util.LinkedList;
import java.util.List;

public class Solution {
    public long countInterestingSubarrays(List<Integer> nums, int modulo, int k) {
        long total = 0;

        int cnt = 0;
        int[] cnts = new int[nums.size() + 1];
        for (int i = 1; i <= nums.size(); i++) {
            if (nums.get(i-1) % modulo == k)
                cnt++;
            cnts[i] = cnt;
        }

        for (int l = 0; l < nums.size(); l++) {
            for (int r = l; r < nums.size(); r++) {
                cnt = cnts[r + 1] - cnts[l];
                if (cnt % modulo == k)
                    total++;
            }
        }
        return total;
    }

    public static void main(String[] args) {
        int[] t = new int[]{3, 2, 4};
        List<Integer> nums = new LinkedList<>();
        nums.add(3);
        nums.add(2);
        nums.add(4);
        int m = 2;
        int k = 1;
        long l = new Solution().countInterestingSubarrays(nums, m, k);
        System.out.println(l);
    }
}
